package planit.controller.impl;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import planit.model.Model;
import planit.model.Person;
import planit.view.PersonDialog;

@SuppressWarnings("serial")
public class CreatePersonController extends AbstractAction {
	private Model model;

	public CreatePersonController(Model model) {
		this.model = model;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		PersonDialog dialog = (PersonDialog)this.getValue("PersonDialog");

		if (dialog.getPersonName().length() > 0) {
			Person p = new Person(dialog.getPersonName());
			p.setEmailAddress(dialog.getPersonMail());
			p.setPhoneNumber(dialog.getPersonPhone());
			model.getSchedule().addPerson(p);
			model.getSchedule().getGroup(1).addPerson(p);
			dialog.dispose();
		} else {
			JOptionPane.showMessageDialog(null,
					"You have to enter the name of the person", "Error",
					JOptionPane.WARNING_MESSAGE);
		}
	}

}

